<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 80%;height: 80%;overflow: hidden;margin:0;font-family:"微软雅黑";}
        #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
        #r-result{height:100%;width:20%;float:left;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=w2ZPR8NagiBPrYZeiFdqbyCrOnaKOizM"></script>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
    <title>设置驾车路线途经点</title>
</head>
<body>
<form>
    起点：<input id = "origin" ></input>- 终点<input id = "end"></input>

    <button>搜索</button>
</form>
<div id="allmap" ></div>
</body>
</html>
<script type="text/javascript">

    // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(113.265105, 23.156072), 11);
    map.enableScrollWheelZoom(true);
    // 编写自定义函数,创建标注
    function addMarker(point,comment){
            var marker = new BMap.Marker(point);
            var label = new BMap.Label(comment,{offset:new BMap.Size(20,-10)});
            marker.setLabel(label);
            marker.addEventListener("click",attribute);
            map.addOverlay(marker);
    }

    $.ajax({
        type : "GET", //提交方式
        url : "/doorDrivingInfo/queryDoorDrivingInfo",//路径
        success : function(data) {//返回数据根据结果进行相应的处理
           for (var i = 0; i < 25; i ++) {
               var point = new BMap.Point(data[i].longitude, data[i].latitude);
               var comment = data[i].doorId;
               addMarker(point,comment);

           }

        }

    });


    //获取覆盖物位置
    function attribute(e){
        var p = e.target;
        var origin = $('#origin').val();
alert(origin);
        if(origin==null||origin==""){

            $("#origin").attr("value",p.getPosition().lng + "," + p.getPosition().lat);// 填充内容
        }
        alert("marker的位置是" + p.getPosition().lng + "," + p.getPosition().lat);
    }







    /* var p1 = new BMap.Point(116.301934,39.977552);
     var p2 = new BMap.Point(116.508328,39.919141);
     var p3 = new BMap.Point(116.365942,39.996165);
     var p4 = new BMap.Point(116.408757,39.995704);

     var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
     driving.search(p1, p2,{waypoints:[p3,p4]});//百度地图API功能*/

</script>